package com.yc.encrypt;

import java.nio.charset.StandardCharsets;

import org.apache.commons.codec.binary.Base64;

import com.google.common.base.Strings;

/**
 * TODO
 * @author yuancan
 * @date  2018-01-26 00:09 
 * @since 3.0.0.3
 */
public class Encry {

	/**
	 * 加密
	 * @param str
	 * @return
	 */
	public static String enCode(String str) {
		if (Strings.isNullOrEmpty(str)) {
			return null;
		}
		return new String(Base64.encodeBase64(str.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
	}
	
	/**
	 * 解密
	 * @param str
	 * @return
	 */
	public static String deCode(String str) {
		if (Strings.isNullOrEmpty(str)) {
			return null;
		}
		return new String(Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
	}
	
	public static void main(String[] args) {
		System.out.println(Encry.enCode("Sheng678"));
	}
}
